home *** CD-ROM | disk | FTP | other *** search
/ Internet Tools (InfoMagic) / Internet Tools.iso / news / moderating / submit.Z / submit
Text File  |  1992-06-08  |  3KB  |  126 lines

  1. : Use /bin/sh
  2.  
  3. # This script is used to submit articles to the NetNews system.
  4. #    (C) 1989 Dave Taylor, Intuitive Systems <taylor@sunworld.com>
  5. #
  6. # I usually invoke it while reading my email within my mailer, 
  7. # as "|submit groupname".  -- Dave Taylor
  8.  
  9.        inewscall="/usr/lib/news/inews -M -h"
  10.         approval="comp-sys-sun-announce@SunWorld.com"
  11.       activefile=/usr/lib/news/active
  12.     followup="comp.sys.sun.misc"
  13.  
  14.        newsgroup=$1
  15.  
  16. # first off, are we called correctly?
  17.  
  18. if [ "$newsgroup" = "" ]
  19. then
  20.   echo "Usage: $0 newgroup-name"
  21.   exit 1
  22. fi
  23.  
  24. # now is this a valid newsgroup?
  25.  
  26. if [ ! -f $activefile ]
  27. then
  28.   echo No active file\?  Where\'s $activefile\?
  29.   exit 1
  30. fi
  31.  
  32. pattern="^$newsgroup"
  33.  
  34. if [ "`egrep $pattern $activefile`" = "" ]
  35. then
  36.   echo Can\'t find newsgroup $newsgroup in $activefile
  37.   exit 1
  38. fi
  39.  
  40. # The next step is to create a temp file that contains the following
  41. # headers and the message body:
  42. #
  43. #    From: <the original line from the mail message>
  44. #       Subject: <the original subject>
  45. #       Distribution: world
  46. #    Organization: <the users org, if one exists>
  47. #     Approved: taylor@sunworld.com
  48.  
  49. # let's save the input stream...
  50.  
  51. cat - > /tmp/submit.$$
  52.  
  53. # note: we might have more than one, hence the "head -1" addition
  54.  
  55.       from="`egrep '^From:' /tmp/submit.$$ | head -1`"
  56.    subject="`egrep '^Subject:' /tmp/submit.$$ | head -1`"
  57.        org="`egrep '^Organization:' /tmp/submit.$$ | head -1`"
  58.  
  59. if [ "$from" = "" ]
  60. then
  61.   from="`head -1 /tmp/submit.$$ | awk -e '{ print \"From: \" $2 }'`"
  62.   if [ "$from" = "" ]
  63.   then
  64.     echo troubles getting a From: line.
  65.     from="From: anonymous"
  66.   fi
  67. fi
  68.  
  69. # create the temp file...
  70.  
  71. echo "$from"            >  /tmp/inews.$$
  72.  
  73. if [ "$subject" = "" ]
  74. then
  75.   echo "Subject: unknown"       >> /tmp/inews.$$
  76. else
  77.   echo "$subject"           >> /tmp/inews.$$
  78. fi
  79.  
  80. echo "Distribution: world"      >> /tmp/inews.$$
  81.  
  82. if [ "$org" != "" ]
  83. then
  84.   echo "$org"            >> /tmp/inews.$$
  85. else
  86.   echo "Organization: "        >> /tmp/inews.$$
  87. fi
  88.  
  89. echo "Approved: $approval"    >> /tmp/inews.$$
  90. echo "Followup-To: $followup"    >> /tmp/inews.$$
  91.  
  92. # and now copy across the body of the message 
  93.  
  94. cat /tmp/submit.$$ | \
  95.   awk -e '{ if (length($0) == 0) ok++; if (ok) print $0 }' \
  96.     >> /tmp/inews.$$
  97.  
  98. # let's let the user look at it and fix it up, perhaps
  99.  
  100. vi /tmp/inews.$$ < /dev/tty
  101.  
  102. # just check that this is what we want to do...
  103.  
  104. echo " "
  105. /bin/echo -n "Are you sure you want to post this to $newsgroup ? "
  106. read answer < /dev/tty
  107. echo " "
  108.  
  109. if [ "$answer" = "no" -o "$answer" = "n" ]
  110. then
  111.   echo posting cancelled.
  112.   /bin/rm -f /tmp/submit.$$ /tmp/inews.$$
  113.   exit 0
  114. fi
  115.  
  116. echo executing the inews call
  117.  
  118. $inewscall -n $newsgroup < /tmp/inews.$$
  119.  
  120. /bin/rm -f /tmp/submit.$$ /tmp/inews.$$
  121.  
  122. echo .. posted without any problems\!
  123.  
  124. exit 0
  125.  
  126.